Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

[repo].js

38 lines960 Bytes

1import React from 'react'
2import Link from 'next/link'
3import fetch from '../../../libs/fetch'
4​
5import { useQuery } from '@tanstack/react-query'
6​
7export default () => {
8 const id =
9 typeof window !== 'undefined' ? window.location.pathname.slice(1) : ''
10​
11 const { status, data, error, isFetching } = useQuery({
12 queryKey: ['team', id],
13 queryFn: () => fetch('/api/data?id=' + id),
14 })
15​
16 return (
17 <div style={{ textAlign: 'center' }}>
18 <h1>{id}</h1>
19 {status === 'pending' ? (
20 'Loading...'
21 ) : status === 'error' ? (
22 <span>Error: {error.message}</span>
23 ) : (
24 <>
25 <div>
26 <p>forks: {data.forks_count}</p>
27 <p>stars: {data.stargazers_count}</p>
28 <p>watchers: {data.watchers}</p>
29 </div>
30 <div>{isFetching ? 'Background Updating...' : ' '}</div>
31 </>
32 )}
33 <br />
34 <br />
35 <Link href="/">Back</Link>
36 </div>
37 )